#!/usr/bin/env python

# Script d'acquisition des Observations provenant
# du module d'acquisition Arduino

# Librairies
import serial
import string
import time
import urllib


class ArduinoListener:

    '''
        Constructeur par dfaut de la classe
    '''
    def __init__(self,portUNix="/dev/ttyAMA0"):
        self = serial.Serial(portUNix,9600,8,parity='N',stopbits=1,timeout=1)


ArduinoSerial = serial.Serial("/dev/ttyAMA0",9600,8,parity='N',stopbits=1,timeout=1)

# Ouverture de la connection
ArduinoSerial.open()

# Boucle de traitement - Ecoute des valeurs
try:
    while True:
        line = ArduinoSerial.readline()
        print ArduinoSerial.getCTS()
        print ArduinoSerial.getDSR()
        print line
        urllib.urlopen("http://192.168.0.5/JCult/index.php?service=newObs&temp=2.0&hum=10&pres=5500&lum=870")
    
except KeyboardInterrupt:
    pass # do cleanup here
    ArduinoSerialtest.flush()
    print 'END'
ArduinoSerialtest.close()
